$(function(){
	$('#tt').datagrid({
		url:'/miguVideoConfig/getMiguVideoConfigListPage'
	});
	
});

function doSearch(){
	var sname=$('#snameId').val();
	var status=$('#sstatusId').combobox('getValue');
	
	$('#tt').datagrid({
		url:'/miguVideoConfig/getMiguVideoConfigListPage',
		queryParams:{
			sname:sname,
			status:status
		}
	});
	$('#tt').datagrid('unselectAll');
}

function nameFormatter(value, row, index){
	return '<a href="javascript:openDetail(' + row.id + ')">'+value+'</a>';
}

function openDetail(id) {
	showMyWindow('详情', '/miguVideoConfig/'+id+'/detail', 800, 600);
}

function statusFormatter(value){
	if(value=='0'){
		return '待启动';
	}if(value=='1'){
		return '启用';
	}else if(value=='2'){
		return '作废'
	}
}

function doAdd() {
	showMyWindow('新增', '/miguVideoConfig/toAdd', 500, 300);
}

function doEdit(){
	var row = $('#tt').datagrid('getSelected');
	if(row==null||row==''){
		$.messager.alert("提示", "请先选择一条记录");
		return;
	}
    if (row){
	    showMyWindow('编辑', '/miguVideoConfig/'+row.id+'/toUpdate', 500, 300);
    } else {
    	showMsg(market.content.title, market.content.tips, alert);
    }
}

function doDel(){
	var record = $('#tt').datagrid('getSelected');
	if(record==null||record==''){
		$.messager.alert("提示", "请先选择一条记录");
		return;
	}
	
	$.messager.confirm('提示', '你确定要删除吗？', function(opt){
		if (opt){
			var id = record.id;
			$.ajax({
				url: '/miguVideoConfig/delete',
				type: 'POST',
				data : {
		            id:id
				},
				success : function(data) {
					if (data.return_code == '1') {
						$.messager.alert(market.content.title, "删除成功");
						$("#tt").datagrid('reload');
						$('#tt').datagrid('unselectAll');
					} else {
						$.messager.alert(market.content.title, data.return_msg);
					}
				},
				error : function(e) {
					$.messager.alert("未知错误");
				}
			})
		}
	});
}

function doCopy() {
	var row = $('#tt').datagrid('getSelections');
	if (row.length == 0) {
		showMsg(market.content.title, "请选择一条记录！", alert);
		return false;
	}
	if (row.length > 1) {
		showMsg(market.content.title, "复制操作只能选择一条记录！", alert);
		return false;
	}
	var record = row[0];
	
	showMyWindow('复制', '/miguVideoConfig/'+record.id+'/toCopy', 800, 600);
}

function doStatus(status){
	var record = $('#tt').datagrid('getSelected');
	if(record==null||record==''){
		$.messager.alert("提示", "请先选择一条记录");
		return;
	}
	
	var msg="你确定要启动吗？";
	if(status=='2'){
		msg="你确定要作废吗？";
	}
	
	$.messager.confirm('提示',msg, function(opt){
		if (opt){
			var id=record.id;
			$.ajax({
				url: '/miguVideoConfig/updateMiguVideoStatus',
				type: 'POST',
				data : {
		            id:id,
		            status:status
				},
				success : function(data) {
					if (data.return_code == '1') {
						$.messager.alert(market.content.title, "操作成功");
						$("#tt").datagrid('reload');
						$('#tt').datagrid('unselectAll');
					} else {
						$.messager.alert(market.content.title, data.return_msg);
					}
				},
				error : function(e) {
					$.messager.alert("未知错误");
				}
			})
		}
	});
	
}

function formatterProvince(value, row, index) {
	var a = '<a href="#" onclick="editProvince(' + "'" + row.id + "'" + ')">配置</a> ';
	return a;
}

function editProvince(id) {
	showMyWindow('省份配置', '/miguVideoConfig/' + id + '/provinceList', 850, 500);
}
